"""
后台登陆方法
"""
from common.base import Base, get_driver
from selenium.webdriver.common.by import By


class BackstageLogin(Base):
    # 点击关闭弹窗
    def click_popup(self):
        self.click((By.XPATH, "//span[@onclick='btnCancel(this)']"))

    # 选择ecseop登录
    def click_ecseop(self):
        self.click((By.ID, "cloudLogin"))

    # 输入用户账号
    def send_keys_username(self, username):
        self.send_keys((By.NAME, "username"), username)

    # 输入用户密码
    def send_keys_password(self, password):
        self.send_keys((By.NAME, "password"), password)

    # 点击登录按钮
    def click_login(self):
        self.click((By.CLASS_NAME, "btn-a"))


if __name__ == '__main__':
    # 创建浏览器驱动
    driver = get_driver()
    backstage_login = BackstageLogin(driver)
    # 访问目标浏览器
    backstage_login.get("http://localhost:8080/ecshop/admin/privilege.php?act=login")
    backstage_login.click_popup()
    backstage_login.click_ecseop()
    backstage_login.send_keys_username("root1234")
    backstage_login.send_keys_password("root1234")
    backstage_login.click_login()
    backstage_login.quit(2)
